package cn.fxl.controller;

import cn.fxl.ajax.AjaxResult;
import cn.fxl.domain.Movie;
import cn.fxl.domain.User;
import cn.fxl.feign.MovieFeign;
import cn.fxl.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    private IUserService iUserService;
    @Autowired
    private MovieFeign movieFeign;
    @GetMapping("user/getmovie")
    public List<Movie> getAll(){
        try {
            return movieFeign.movieGetAll();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    @PostMapping("/buyticket")
    public AjaxResult buyticket(@RequestBody User user){
        try {
           return iUserService.buyticket(user);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"失败");
        }
    }
    @GetMapping("/user/watchmovie/{id}")
    public AjaxResult userWatchMovie(@PathVariable("id") Long id){
        try {
            return movieFeign.moveGetOne(id);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"电影票过期了");
        }
    }
    @PostMapping("/user/add")
    public AjaxResult userAdd(@RequestBody User user){
        try {
            return iUserService.userAdd(user);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult();
        }
    }
}
